﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CrankShaftAnalysisSystem
{
    class Tools
    {
        public static ushort LowWord(uint value)
        {
            var ret = value & 0xFFFF;
            return (ushort)ret;
        }

        public static ushort HighWord(uint value)
        {
            var ret = (value & 0xFFFF0000) >> 16;
            return (ushort)ret;
        }

        public static bool GetBitState(ushort reg, ushort mask)
        {
            return (reg & mask) > 0;
        }

        public static double ReduceRadians(double ang)
        {
            //将角度限制在 - pi ~pi
            while (Math.Abs(ang) > Math.PI)
            {
                if (ang > 0) ang = ang - Math.PI * 2;
                else ang = ang + Math.PI * 2;
            }
            return ang;
        }
    }
}
